﻿



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>分店销售单据汇总查询</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" type="text/css" href="/Styles/demo.css" />
    <script src="/scripts/boot.js" type="text/javascript"></script>
    <script type="text/javascript" src="/Scripts/jquery.PrintArea.js"></script>
</head>
<body>
    <div class="mini-fit">
        <div class="mini-splitter" style="width: 100%; height: 100%;">
            <div size="240" showcollapsebutton="true">
                <div class="mini-toolbar" style="padding: 2px; border-top: 0; border-left: 0; border-right: 0;">
                    <input class="mini-textbox" id="treekey" style="width:150px;" />
                    <a class="mini-button" iconcls="icon-search" plain="true" onclick="treesearch">查找</a>
                </div>
                <div class="mini-fit">
                    <ul id="tree1" class="mini-tree" url="/Archives/SearchAllranchesForTree" style="width: 100%;"
                        showtreeicon="true" textfield="bName" idfield="Id" parentfield="pid" resultastree="false">
                    </ul>
                </div>
            </div>
            <div showcollapsebutton="true" id="printArea">
                <div style="width: 100%">
                    <div class="mini-toolbar" style="border-bottom: 0; padding: 0px;">
                        <table style="width: 100%;">
                            <tr>
                                <td style="width: 100%;">
                                    <a class="mini-button" iconcls="icon-printer" onclick="print()" plain="true">打印</a>
                                    <span class="separator"></span>
                                </td>
                                <td style="white-space: nowrap;">
                                    <input id="dateS" class="mini-datepicker" value="@DateTime.Now.ToString("yyyy-MM-01")" emptytext="开始时间" />
                                    ~<input id="dateE" class="mini-datepicker" value="@Convert.ToDateTime(DateTime.Now.AddMonths(1).ToString("yyyy-MM-01")).AddDays(-1).ToString("yyyy-MM-dd")" emptytext="结束时间" />
                                    <a class="mini-button" onclick="search()">查询</a>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
                <div id="datagrid1" class="mini-datagrid" url="/Query/SearchBranchRetail"
                    style="width: 100%; height: 93%;" idfield="Id" allowresize="false" sizelist="[20,30,50,100]"
                    pagesize="20" multiselect="true" ondrawsummarycell="onDrawSummaryCell" showSummaryRow="true"
                    showpager="true">
                    <div property="columns">
                        <div type="indexcolumn" width="30">
                        </div>
                        
                        <div field="Id" headeralign="center" align="center" width="60">
                            销售单号</div>
                        <div field="RtDate" headeralign="center" align="center" width="60" dateformat="yyyy-MM-dd">
                            销售时间</div>
                        <div field="RtType" headeralign="center" align="center" width="60">
                            销售方式</div>
                        <div field="SaleQty" headeralign="center" align="center" width="60" summaryType="sum">
                            数量</div>
                        <div field="SaleMoney" headeralign="center" align="center" width="60" summaryType="sum">
                            销售金额</div>
                        <div field="DiscountMoney" headeralign="center" align="center" width="80" summaryType="sum">
                            折扣金额</div>
                        <div name="action" width="120" headeralign="center" align="center" renderer="onActionRenderer2"
                            cellstyle="padding:0;">
                            管理</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        mini.parse();


        var grid = mini.get("datagrid1");


        grid.load();
        //对"createtime"字段，进行降级排序
        grid.sortBy("Id", "desc");


        $("#key").bind("keydown", function (e) {
            if (e.keyCode == 13) {
                search();
            }
        });



        function onActionRenderer(e) {
            var grid = e.sender;
            var record = e.record;
            var uid = record.Id;
            var rowIndex = e.rowIndex;

            var s = ' <a class="Edit_Button" href="javascript:editRow(\'' + uid + '\')" >编辑</a>'
                + ' <a class="Delete_Button" href="javascript:if(confirm(\'确定要删除这条记录吗？\')){deleteItem(\'' + uid + '\')}">删除</a>';
            return s;
        }



        function remove() {
            var rows = grid.getSelecteds();
            if (rows.length > 0) {
                if (confirm("确定删除选中记录？")) {
                    var ids = [];
                    for (var i = 0, l = rows.length; i < l; i++) {
                        var r = rows[i];
                        ids.push(r.Id);
                    }
                    var id = ids.join(',');
                    grid.loading("操作中，请稍后......");
                    deleteItem(id);
                }
            } else {
                alert("请选中一条记录");
            }
        }
        var tree = mini.get("tree1");
        tree.on("nodeselect", function (e) {
            if (e.isLeaf) {
                search();
            } else {
                grid.setData([]);
                grid.setTotalCount(0);
            }
        });

        function doSearch() {
            if (tree.getSelectedNode()) {
                grid.load({
                    EnCode: tree.getSelectedNode().Id,
                    dateS: mini.get("dateS").getValue(),
                    dateE: mini.get("dateE").getValue()
                });
            }
            else {
                grid.setData([]);
                grid.setTotalCount(0);
            }
        }

        function showSearchWindow() {
            var win = mini.get("searchWindow");
            win.show();
        }
        function advSearch() {
            var frm = new mini.Form("frmAdv");
            grid.load(frm.getData(true));
            var win = mini.get("searchWindow");
            win.hide();
        }
        function search() {
            grid.load({
                bCode: tree.getSelectedNode().Id,
                dates: mini.get("dateS").getFormValue(),
                datee: mini.get("dateE").getFormValue()
            });
        }
        function treesearch() {
            var value = mini.get("treekey").getValue();
            tree.load("/Archives/SearchAllranches/" + value);
        }
        function onActionRenderer2(e) {
            var grid = e.sender;
            var record = e.record;
            var uid = record.Id;
            var rowIndex = e.rowIndex;

            var s = ' <a class="Edit_Button" href="javascript:viewRow(\'' + uid + '\')" >明细查看</a>';
            return s;
        }
        function viewRow(id) {
            mini.open({
                url: "/Query/RetailView/" + id + "?readonly=true",
                title: "销售查看",
                iconCls: "icon-cart",
                allowResize: false,
                width: 700,
                height: 480,
                onload: function () {
                },
                ondestroy: function (action) {

                    grid.reload();
                }
            });
        }
        function onDrawSummaryCell(e) {
            try {
                if (e.result.Statistics) {
                    var statics = e.result.Statistics;
                    var grid = e.sender;


                    if (e.field == "SupCode") {
                        e.cellHtml = "记录数：" + statics.count;
                    }
                    if (e.field == "detailCount") {
                        e.cellHtml = "商品种类:" + statics.detailCount;
                    }
                    if (e.field == "count") {
                        e.cellHtml = "货物总量：" + statics.goodscount;
                    }
                    if (e.field == "amount") {
                        e.cellHtml = "总额：" + statics.amount;
                    }
                }
            }
            catch (e) { }
        }
        function print() {
            $("#printArea tr").each(function () {
                $(this).find("td").last().hide();
            });
            var oldHeight = $("#printArea .mini-grid-body").first().height();
            $("#printArea .mini-grid-body").first().height(($("#printArea tr").size() - 7) * 23)
            $("#printArea").printArea();
            $("#printArea .mini-grid-body").first().height(oldHeight);

            $("#printArea tr").each(function () {
                $(this).find("td").last().show();
            });
        }
        </script>
</body>
</html>
